<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人信息</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="hg-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta http-equiv="Cache-Control" content="no-siteapp" />

    <link rel="stylesheet" href="/layui/css/layui.css">
    <link  href="/hg-layui-admin-ui/css/font.css">
    <script src="/js/jquery-1.8.3.min.js"></script>
    <script src="/layui/layui.js"></script>

    <style>

    </style>
</head>
<body>
    <!--管理员-->
    <form class="layui-form layui-row changePwd" id="admin" style="margin-top: 5%;display: none"  >
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input  id="adminId"  name="adminId" type="hidden"/>
                    <input type="text"  value="" style="width: 350px" placeholder="请输入用户名" lay-verify="required|oldPwd"  id="adminName" name="adminName"  class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-bg-green" id="change_t" lay-filter="change_t" >立即修改</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>

    <!--学生-->
    <form class="layui-form" id="user" action="" style="margin-top: 50px;margin-left:4%;display: none;">

                <input type="hidden" id="xsid"  name="xsid">

                <!-- 新增  -->
                <div class="layui-form-item" >
                    <label class="layui-form-label" style="width: 65px;"><span  >学生学号</span><span style="color: red">*</span></label>
                    <div class="layui-input-inline">
                        <input type="text" id="xsxhs" name="xsxhs"  style="width: 270px;" placeholder="学生学号" class="layui-input qyzzlname" >
                    </div>

                    <label class="layui-form-label" style="width: 170px"><span id="qyzzlmksjorfr">学生姓名</span><span style="color: red">*</span></label>
                    <div class="layui-input-inline">
                        <input type="text" id="xsxms"   name="xsxms" style="width: 270px;"  placeholder="学生姓名"  class="layui-input" />
                    </div>
                </div>



                <div class="layui-form-item" >
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 65px"><span>密码</span><span style="color: red">*</span></label>
                        <div class="layui-input-inline">
                            <input type="text" id="password"  style="width: 270px;"  name="password"   placeholder="密码"  class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-inline" style="width:50%" >
                        <label class="layui-form-label"  style="width: 155px">性别</label>
                        <div class="layui-input-block">
                            <input type="radio" name="xsxb" value="男" title="男  " checked="">
                            <input type="radio" name="xsxb" value="女" title="女   " >
                        </div>
                    </div>

                </div>

                <div class="layui-form-item" >

                    <label class="layui-form-label" style="width: 65px;"><span id="qyzzlsfzhorgddh">入学年级</span></label>
                    <div class="layui-input-inline">
                        <input type="text" id="rxnjs" name="rxnjs" style="width: 270px;"  placeholder="入学年级" class="layui-input" >
                        <!-- lay-verify="required"  -->
                    </div>

                    <div class=""  id="qyzzllxdz" >
                        <label class="layui-form-label" style="width: 170px;">联系电话</label>
                        <div class="layui-input-inline">
                            <input type="text" id="lxdh"  name="lxdh" placeholder="联系电话" style="width: 270px;"  class="layui-input"  >
                        </div>
                    </div>
                </div>

                <div class="layui-form-item" >

                    <label class="layui-form-label" style="width: 65px;"><span >邮箱</span></label>
                    <div class="layui-input-inline">
                        <input type="email" id="email" name="email" style="width: 270px;"   placeholder="邮箱" class="layui-input" >
                        <!-- lay-verify="required"  -->
                    </div>
                    <label class="layui-form-label" style="width: 170px;">身份证</label>
                    <div class="layui-input-inline">
                        <input type="text" id="sfz"  name="sfz" placeholder="身份证" style="width: 270px;"  class="layui-input"  >
                    </div>
                </div>
                <div class="layui-form-item" >

                    <label class="layui-form-label" style="width:65px;"><span >住址</span></label>
                    <div class="layui-input-inline">
                        <input type="text" id="address" name="address"  style="width: 270px;"   placeholder="住址" class="layui-input" >
                        <!-- lay-verify="required"  -->
                    </div>

                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-bg-green" id="change_xs" lay-filter="change_xs" >立即修改</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>

    </form>


    <!--教师-->
    <form class="layui-form" id="teacher"  style="margin-top: 50px;margin-left:4%;display: none;">

        <input type="hidden" id="jsid"  name="jsid">

        <!-- 新增  -->
        <div class="layui-form-item" >
            <label class="layui-form-label" style="width: 65px;"><span  >教师编号</span><span style="color: red">*</span></label>
            <div class="layui-input-inline">
                <input type="text" id="jsxh" name="jsxh"  style="width: 270px;" placeholder="教师编号" class="layui-input qyzzlname" >
            </div>

            <label class="layui-form-label" style="width: 170px"><span >教师姓名</span><span style="color: red">*</span></label>
            <div class="layui-input-inline">
                <input type="text" id="jsxm"   name="jsxm" style="width: 270px;"  placeholder="学生姓名"  class="layui-input" />
            </div>
        </div>

        <div class="layui-form-item" >
            <div class="layui-inline"  >
                <label class="layui-form-label"  style="width: 60px">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="jsxb" value="男" title="男  " checked="">
                    <input type="radio" name="jsxb" value="女" title="女   " >
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 209px"><span>密码</span><span style="color: red">*</span></label>
                <div class="layui-input-inline">
                    <input type="text" id="jspassword"  style="width: 270px;"  name="jspassword"   placeholder="密码"  class="layui-input" />
                </div>
            </div>


        </div>

        <div class="layui-form-item" >

            <label class="layui-form-label" style="width: 65px;"><span >课程</span></label>
            <div class="layui-input-inline" style="width: 270px;">
                <select id="jskc"  lay-search="" name="jskc" >

                </select>
            </div>

            <div class=""   >
                <label class="layui-form-label" style="width: 90px;">职务</label>
                <div class="layui-input-inline">
                    <input type="text" id="jszw"  name="jszw" placeholder="职务" style="width: 270px;"  class="layui-input"  >
                </div>
            </div>
        </div>

        <div class="layui-form-item" >

            <label class="layui-form-label" style="width: 65px;"><span >邮箱</span></label>
            <div class="layui-input-inline">
                <input type="email" id="jsemail" name="jsemail" style="width: 270px;"   placeholder="邮箱" class="layui-input" >
                <!-- lay-verify="required"  -->
            </div>
            <label class="layui-form-label" style="width: 170px;">联系电话</label>
            <div class="layui-input-inline">
                <input type="text" id="jslxdh"  name="jslxdh" placeholder="联系电话" style="width: 270px;"  class="layui-input"  >
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label" style="width: 65px;">身份证</label>
            <div class="layui-input-inline">
                <input type="text" id="jssfz"  name="jssfz" placeholder="身份证" style="width: 270px;"  class="layui-input"  >
            </div>
            <label class="layui-form-label" style="width:170px;"><span >住址</span></label>
            <div class="layui-input-inline">
                <input type="text" id="jsaddress" name="jsaddress"  style="width: 270px;"   placeholder="住址" class="layui-input" >
                <!-- lay-verify="required"  -->
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-bg-green" id="change_js" lay-filter="change_js" >立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>





</body>
</html>
<script>
    //获取值回显
    layui.use([ 'form', 'layer', 'laydate', 'table', 'laytpl' ],function() {
        var layer = layui.layer;
        var form = layui.form;
        $.ajax({
            type:"POST",
            url:"/getUserInfo",
            dataType:"json",
            async : true, //是否异步
            success:function (data) {
                if(data.roleId==1){
                    $("#admin").show();
                    $("#adminName").val(data.username);
                    $("#adminId").val(data.id);
                }else if(data.roleId==3){
                    $("#user").show();
                    //根据缓存的id去查找值回显
                    cshxs();
                }else if(data.roleId==4){
                    $("#teacher").show();
                    getSelect();
                    setTimeout(function(){
                        cshjs();
                    },200)
                }

            },
            error: function (data,type, err) {
                console.log("ajax错误类型："+type);
                console.log(err);
                layer.msg('删除失败！');
            }
        });

    });

    /*管理员*/
    $("#change_t").click(function () {
        var username = $("#adminName").val();
        var id = $("#adminId").val();
        if(username==''){
            layer.msg("用户名不可为空！");
            return false;
        }
        var user = {
            username:username,
            id:id,
        };
        $.ajax({
            type:"POST",
            data:user,
            url:"setUsernames",
            dataType:"json",
            async : true, //是否异步
            success:function (data) {
                layer.msg("保存成功！");
                cshamdin()
            },
            error: function (data,type, err) {
                console.log("ajax错误类型："+type);
                console.log(err);
                layer.msg('删除失败！');
            }
        });

        return false;
    });

    /*修改后不可从缓存取*/
    function cshamdin(){

        $.ajax({
            type:"POST",
            url:"getUser",
            dataType:"json",
            async : true, //是否异步
            success:function (data) {
                $("#adminName").val(data.username);
                $("#adminId").val(data.id);
            },
            error: function (data,type, err) {
                console.log("ajax错误类型："+type);
                console.log(err);
                layer.msg('删除失败！');
            }
        });

    }

    /*学生*/
    function cshxs(){
        $.ajax({
            type:"POST",
            url:"getStudent",
            dataType:"json",
            async : true, //是否异步
            success:function (data) {
                $("#xsxhs").val(data.number);
                $("#xsxms").val(data.name);
                $("#password").val(data.password);

                if(data.sex=='男'){
                    $(":radio[name='xsxb'][value= '男']").prop("checked", true);
                }else{
                    $(":radio[name='xsxb'][value= '女']").prop("checked", true);
                }
                $("#rxnjs").val(data.rxnj);
                $("#lxdh").val(data.phone);
                $("#email").val(data.email);
                $("#sfz").val(data.sfz);
                $("#xsid").val(data.id);
                $("#address").val(data.address);
                layui.form.render();
            },
            error: function (data,type, err) {
                console.log("ajax错误类型："+type);
                console.log(err);
                layer.msg('删除失败！');
            }
        });
    }

    /*学生保存按钮*/
    $("#change_xs").click(function(){

        var xsxhs = $("#xsxhs").val();
        var id = $("#xsid").val();
        var xsxms = $("#xsxms").val();
        var password = $("#password").val();
        var xsxb = $("input[name='xsxb']:checked").val();//性别
        var rxnjs = $("#rxnjs").val();
        var lxdh =  $("#lxdh").val();
        var email =  $("#email").val();
        var sfz =  $("#sfz").val();
        var address =  $("#address").val();


        if(xsxhs == null || xsxhs == ""){
            layer.msg("学生学号不能为空！");
            return;
        }
        if(xsxms == null || xsxms == ""){
            layer.msg("学生姓名不能为空！");
            return;
        }
        if(password == null || password == ""){
            layer.msg("登录密码不能为空！");
            return;
        }

        if(password!=null){
            if(password.length<6){
                layer.msg("登录密码不能小于6位！");
                return;
            }
        }
        var mobilevalid = /^[1]([3-9])[0-9]{9}$/;
        if (lxdh!=''&&!mobilevalid.test(lxdh)) {
            layer.msg("请输入正确的手机号码！");
            return false;
        }

        if(sfz!=''){
            var reg15 = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/; //身份证号码正则
            if (!reg15.test(sfz)) {
                layer.msg("请输入正确的身份证号！");
                return false;
            }
        }
        console.log("打印值编辑");
        var student ={
            id:id,
            number : xsxhs,
            name : xsxms,
            password : password,
            rxnj : rxnjs,
            phone : lxdh,
            sex : xsxb,
            email : email,
            sfz : sfz,
            address : address,
        };

        console.log(student);
        $.ajax({
            type:"POST",
            url:"editxs",
            data:student,
            success:function (data) {
                layer.msg("修改成功");
                cshxs();
            },
            error: function (data,type, err) {
                console.log("ajax错误类型："+type);
                console.log(err);

                layer.alert("修改失败", {
                        icon: 6
                    },
                    function () {
                    });
            }
        });
        return  false;
    });



    /*教师*/
    function cshjs(){
        $.ajax({
            type:"POST",
            url:"/admin/user/getTeacher",
            dataType:"json",
            async : true, //是否异步
            success:function (data) {
                console.log(data)
                $("#jsxh").val(data.number);
                $("#jsxm").val(data.name);
                $("#jspassword").val(data.password);

                if(data.sex=='男'){
                    $(":radio[name='jsxb'][value= '男']").prop("checked", true);
                }else{
                    $(":radio[name='jsxb'][value= '女']").prop("checked", true);
                }
                $("#jskc").val(data.kc);
                $("#jszw").val(data.zw);
                $("#jslxdh").val(data.phone);
                $("#jsemail").val(data.email);
                $("#jssfz").val(data.sfz);
                $("#jsid").val(data.id);
                $("#jsaddress").val(data.address);
                layui.form.render();
            },
            error: function (data,type, err) {
                console.log("ajax错误类型："+type);
                console.log(err);
                layer.msg('删除失败！');
            }
        });
    }

    function getSelect(){
        $.ajax({
            type:"POST",
            url:"/admin/ktinfo/getAllKtinfo",
            data:{ktmc:""},
            dataType:"json",
            async : true, //是否异步
            success:function (data) {
                console.log("---9991111111")
                console.log(data)
                var str = "<option value=''>请选择课堂</option> ";
                if(data.rows.length>0){
                    var datas = data.rows;
                    console.log(datas.length)
                    for (let i = 0; i < datas.length ; i++) {
                        str += "<option value="+datas[i].id+">"+datas[i].ktmc+"</option>";
                    }
                }else{
                    str = "<option value=''>暂无课堂信息</option> ";
                }
                $("#jskc").html(str);

            },
            error: function (data,type, err) {
                console.log("ajax错误类型："+type);
                console.log(err);
                layer.msg('删除失败！');
            }
        });
    };


    /*教师保存按钮*/
    $("#change_js").click(function(){
        var id = $("#jsid").val();
        var jsxhs = $("#jsxh").val();
        var jsxms = $("#jsxm").val();
        var password = $("#jspassword").val();
        var jsxb = $("input[name='jsxb']:checked").val();//性别
        var jskc = $("#jskc").val();
        var jszw =  $("#jszw").val();
        var lxdh =  $("#jslxdh").val();
        var email =  $("#jsemail").val();
        var sfz =  $("#jssfz").val();
        var address =  $("#jsaddress").val();


        if(jsxhs == null || jsxhs == ""){
            layer.msg("教师编号不能为空！");
            return;
        }
        if(jsxms == null || jsxms == ""){
            layer.msg("教师姓名不能为空！");
            return;
        }
        if(password == null || password == ""){
            layer.msg("登录密码不能为空！");
            return;
        }

        if(password!=null){
            if(password.length<6){
                layer.msg("登录密码不能小于6位！");
                return;
            }
        }
        var mobilevalid = /^[1]([3-9])[0-9]{9}$/;
        if (lxdh!=''&&!mobilevalid.test(lxdh)) {
            layer.msg("请输入正确的手机号码！");
            return false;
        }

        if(sfz!=''){
            var reg15 = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/; //身份证号码正则
            if (!reg15.test(sfz)) {
                layer.msg("请输入正确的身份证号！");
                return false;
            }
        }

        var student ={
            id:id,
            number : jsxhs,
            name : jsxms,
            password : password,
            kc : jskc,
            zw : jszw,
            phone : lxdh,
            sex : jsxb,
            email : email,
            sfz : sfz,
            address : address,
        };

        $.ajax({
            type:"POST",
            url:"editjs",
            data:student,
            success:function (data) {
                layer.msg("修改成功");
                cshjs();
            },
            error: function (data,type, err) {
                console.log("ajax错误类型："+type);
                console.log(err);

                layer.alert("修改失败", {
                        icon: 6
                    },
                    function () {
                    });
            }
        });

        return  false;
    });

</script>